#!/usr/bin/env python
#coding=utf-8 

from urllib import urlretrieve
def firstNonBlank(lines):
	for eachLine in lines:
		if not eachLine.strip():
			continue
		else:
			return eachLine

def firstLast(webpage):
	f = open(webpage)
	lines = f.readlines()
	f.close()
	print firstNonBlank(lines),# 第一行
	lines.reverse()
	print firstNonBlank(lines),# 最后一行

def download(url='http://www.baidu.com',
	process=firstLast):
	try:
		retval = urlretrieve(url)[0]
	except IOError:
		retval = None
	if retval: # do some processing
		process(retval)

if __name__  == '__main__':
	download()